home *** CD-ROM | disk | FTP | other *** search
/ New Masters of Flash / New Masters of Flash.iso / pc / MOVIES / 05.dir / 00220_Text_text16.txt < prev    next >
Text File  |  2000-10-01  |  4KB  |  36 lines

  1. Frame 7: 
  2. (label Calc 3d) 3d Calc
  3.  
  4. This frame contains the script that is responsible for doing the 3D calculations, drawing the vertices and connecting them with lines.
  5.  
  6. The script on this frame is also called from the main looping script and is responsible for doing the actual 3Dcalculations and converting the 3D coordinates (X, Y, Z) to 2d X, Y) coordinates so that the points can be drawn on screen. It is important to understand that any 3D environment on a computer screen is an illusion of 3D space. A screen is essentially a 2D surface and the trick is to arrive at X and Y coordinates that can be used to draw the pointΓÇÖs position on screen, and a Z coordinate that can be used to scale the points in order to create a sense of depth.
  7. The script uses the "x", "y" and "z" coordinates for each point (set in frame 2) and the rotation angles (Variable: "Yangle" and "Xangle" to arrive at values for the X, Y and Z positions.
  8.  
  9. The calculations for rotation around all three axis will look something like the equation below and requires a value for the X rotation, Y rotation and Z rotation and values for "x", "y" and "z". The calculation is done nine times (once for each vertex with the value of Variable: "c" corresponding to the vertex number). This is where the Sine and Cosine values (set in frame 1) comes into play.
  10.  
  11. Note that the below equations contains the formula for calculating the X and Y coordinates on a circle on a single plane. I covered this earlier ( remember: radius * cos  (angle) for X 0and radius * sin (angle) for Y.The reason for this is that we are basicly calculating a points position on a circular path, not only for one plane, but for three (one for each axis) with "x","y" and "z" representing the radius or the distance away from the center of rotation on each axis (the coordinates set in frame 2):
  12.  
  13. Rotation around X-axis:
  14. ypos = y * cos (Xangle) - z * sin(Xangle)
  15. zpos = y * sin(Xangle) + z * cos(Xangle)
  16.  
  17. Rotation around Y-axis
  18. xpos = x * cos(Yangle) + zpos * sin(Yangle)
  19. zpos = -x *sin(Yangle) + zpos * cos(Yangle)
  20.  
  21. Rotation around Z-axis:
  22. xpos = xpos * cos(Zangle) ΓÇö ypos * sin(Zangle)
  23. ypos = xpos * sin(Zangle) + ypos* cos(Zangle)
  24. Because the X and Y position of "/TrailerObj" was used to generate the rotation angles, there is no value set for the rotation around the Z-axis. You can therefore take a bit of a shortcut and only calculate the rotation around the X and Y-axis. YouΓÇÖll see the difference between the two methods in the way the 3D object reacts when rotated.
  25.  
  26. Calculating the rotation for X, Y and Z as IΓÇÖve shown you would be a more thorough way to do it, but since I was quite happy to lose two lines of calculations, I missed out Z and did it this way:
  27.  
  28. Rotation around Y-axis      
  29. zpos = z * cos(Yangle)  ΓÇö x * sin(Yangle)
  30. xpos = z * sin"(Yangle) + x * cos(Yangle)
  31.  
  32. Rotation around X-axis
  33. ypos = y  * cos(Xangle) - zpos * sin(Xangle)
  34. zpos = y  * sin(Xangle) + zpos * cos(Xangle)
  35. Now that the individual vertices are drawn and scaled according to their depth, itΓÇÖs time to give these floating points some structure by connecting them with lines. Because it is not possible to plot individual vertex coordinates for a line in Flash we have to find another way round.  This can be done by using a movie clip that contains a single diagonal hairline. The idea is to duplicate "/line" and to put the new instance at the same coordinate as the first point and then scaling it to stretch across to the next point. Because the line is a 100 units high and wide its scale percentage and actual size has the same value, in other words, if we set its Y scale to 50% of its original height of 100 units, it would scale down to 50 units etc. Note that that the movie clip wonΓÇÖt scale a negative value unless it is duplicated. (Scaling a movie clip that is not a duplicate with a negative value can yield some unexpected results.)
  36.